package com.whli.autumn.mall.metadata.service.impl;

import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.whli.autumn.core.app.constant.AppConstants;
import com.whli.autumn.core.extend.service.impl.BaseServiceImpl;
import com.whli.autumn.mall.metadata.domain.dto.perunit.PerUnitQueryDTO;
import com.whli.autumn.mall.metadata.domain.entity.PerUnit;
import com.whli.autumn.mall.metadata.mapper.PerUnitMapper;
import com.whli.autumn.mall.metadata.service.IPerUnitService;
import com.whli.autumn.mall.metadata.domain.vo.perunit.PerUnitVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>计量单位业务实现</p>
 *
 * @author whli
 * @version 1.0.0
 * @since 2023-05-22 13:57
 */
@Service("perUnitService")
public class PerUnitServiceImpl extends BaseServiceImpl<PerUnit, PerUnitMapper> implements IPerUnitService {

    @Override
    public List<PerUnitVO> listPerUnit(PerUnitQueryDTO entity) {
        entity.setIsEnable(AppConstants.YES);
        return super.listAll(entity);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean enable(String id) {
        if (StringUtils.isEmpty(id)) {
            return false;
        }
        int rows = mapper.updateStatus(id, AppConstants.YES);
        return SqlHelper.retBool(rows);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean disable(String id) {
        if (StringUtils.isEmpty(id)) {
            return false;
        }
        int rows = mapper.updateStatus(id, AppConstants.NO);
        return SqlHelper.retBool(rows);
    }

}
